//
//  BJPayCoinsPopView.m
//  BowJoy
//
//  Created by  on 2024/5/27.
//

#import "BJPayCoinsPopView.h"
static CGFloat leftMain = 60;//白色背景离左右距离
@interface BJPayCoinsPopView()
@property (nonatomic,strong) UIView *bottomPopView;
@property (nonatomic,assign) CGFloat bottomPopViewHeight;//视图的高度
@property (nonatomic,strong)UIImageView *bgImageBView;


@property (nonatomic,strong)UILabel *decLabel;
@property (nonatomic,strong)UIButton *YESBtn;
@property (nonatomic,strong)UIButton *NOBtn;

@property (nonatomic)NSString *title;

@end

@implementation BJPayCoinsPopView

- (instancetype)initWithTitle:(NSString *)title{
    self = [super init];
    if (self) {
        self.title = title;
        [self initSubViews];
    }
    return self;
}
-(void)initSubViews{
    
    self.bottomPopViewHeight = kScreenH -120;

    [self addSubview:self.bottomPopView];
    self.bottomPopView.makeCons(^{
        make.left.constants(leftMain);
        make.right.constants(-leftMain);
        make.center.constants(0);
    });
    
    [self.bottomPopView addSubview:self.bgImageBView];
    self.bgImageBView.makeCons(^{
        make.edge.constants(0);
    });

    
    
    [self.bottomPopView addSubview:self.decLabel];
    self.decLabel.makeCons(^{
        make.leading.constants(23);
        make.trailing.constants(-23);
        make.top.view(self.bottomPopView).top.constants(20);
    });
    
    
    [self.bottomPopView addSubview:self.YESBtn];
    self.YESBtn.makeCons(^{
        make.left.constants(20);
        make.top.view(self.decLabel).bottom.constants(10);
        make.width.constants(100);
        make.height.constants(40);
        make.bottom.constants(-20);
    });
    
    [self.bottomPopView addSubview:self.NOBtn];
    self.NOBtn.makeCons(^{
        make.right.constants(-20);
        make.top.view(self.decLabel).bottom.constants(10);
        make.width.constants(100);
        make.height.constants(40);
        make.bottom.constants(-20);
    });
    
  
}
- (NSString *)getDate{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
     
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDate *currentDate = [NSDate date];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    return dateString;
}


-(void)showView{
    CGFloat whiteViewWidth = kScreenW-2*leftMain;
    self.frame = [UIScreen mainScreen].bounds;
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    self.backgroundColor = PopViewBackColor;

}

#pragma mark - 点击背景关闭视图
-(void)closeView
{
    [self removeFromSuperview];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}
-(void)clickOKBtn{
    if (self.updateOKBack) {
        self.updateOKBack();
    }

    [self closeView];
}

-(void)agreeBtnClick{
    
    
}



-(UIView *)bottomPopView
{
    if (_bottomPopView == nil) {
        _bottomPopView = [[UIView alloc] init];
        _bottomPopView.backgroundColor = [UIColor clearColor];
        _bottomPopView.layer.cornerRadius = 12;
        _bottomPopView.layer.masksToBounds = YES;
    }
    return _bottomPopView;
}

- (void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}
-(UIImageView *)bgImageBView
{
    if (_bgImageBView == nil) {
        _bgImageBView = [[UIImageView alloc]init];
        _bgImageBView.contentMode = UIViewContentModeScaleAspectFill;
        _bgImageBView.userInteractionEnabled = YES;
        _bgImageBView.image = [UIImage imageNamed:@"icon_home_pop_rewardBg"];
    }
    return _bgImageBView;
}

 

-(UILabel *)decLabel
{
    if (_decLabel == nil) {
        _decLabel = [[UILabel alloc]init];
        _decLabel.textColor = [UIColor colorWithHexString:@"#666666"];
        _decLabel.font = [UIFont systemFontOfSize:16];
        _decLabel.textAlignment = NSTextAlignmentCenter;
        _decLabel.text = self.title;
        _decLabel.numberOfLines = 0;
    }
    return _decLabel;
}


-(UIButton *)YESBtn
{
    if (_YESBtn == nil) {
        _YESBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _YESBtn.backgroundColor = [UIColor blackColor];
        [_YESBtn setTitle:@"YES" forState:UIControlStateNormal];
        [_YESBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _YESBtn.layer.cornerRadius = 20;
        _YESBtn.layer.masksToBounds = YES;
        [_YESBtn addTarget:self action:@selector(clickOKBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _YESBtn;
}
-(UIButton *)NOBtn
{
    if (_NOBtn == nil) {
        _NOBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _NOBtn.backgroundColor = [UIColor blackColor];
        [_NOBtn setTitle:@"NO" forState:UIControlStateNormal];
        [_NOBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _NOBtn.layer.cornerRadius = 20;
        _NOBtn.layer.masksToBounds = YES;
        [_NOBtn addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];
    }
    return  _NOBtn;
}


@end
